package com.example.date;

import org.junit.Test;

import java.time.*;
import java.time.format.DateTimeFormatter;

/**
 * @author readpage
 * @create 2022-10-25 14:58
 */
public class InstanceTest {
    @Test
    public void test() {
        LocalDateTime start = LocalDateTime.parse("1970-01-01 00:00:00", DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        System.out.println(start.toInstant(ZoneOffset.of("+0")).getEpochSecond());
        // 1.创建Instance的对象，获取此刻时间信息
        Instant now = Instant.now();
        System.out.println(now);

        // 2.获取总秒数
        long second = now.getEpochSecond();
        System.out.println(second);

        //不够一秒的纳秒数
        int nano = now.getNano();
        System.out.println(nano);

        Instant instant = now.plusNanos(111);
        System.out.println("默认时区:" + ZoneId.systemDefault());

    }

    @Test
    public void test2() {
        Instant start = Instant.now();
        for (int i = 0; i < 100000000; i++) {
        }
        Instant end = Instant.now();
        long l2 = System.currentTimeMillis();

        Duration between = Duration.between(start, end);
        long l = between.toMillis();
        System.out.println("程序执行了" + l + "毫秒");
    }
}
